package com.seabook.store.goodmgr.domain;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.springframework.util.StringUtils;

public class Product implements java.io.Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 6016744182769779655L;

    private Category category = new Category();
    
    private int categoryId;

    private int productId;

    private String productNo;

    private String name;

    private String description;

    private String status;

    private String iconUrl;

    private List<String> imgUrls;

    private Date addedDate;

    private Date endDate;  
    
    private int amount;
    
    private int curAmount;
    
    private double unitPrice;
    
    private double unitPriceCur;

    public String getIconUrl() {
        return iconUrl;
    }

    public void setIconUrl(String iconUrl) {
        this.iconUrl = iconUrl;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public int getProductId() {
        return productId;
    }

    public void setProductId(int productId) {
        this.productId = productId;
    }

    public String getProductNo() {
        return productNo;
    }

    public void setProductNo(String productNo) {
        this.productNo = productNo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public List<String> getImgUrls() {
        return imgUrls;
    }

    public void setImgUrls(List<String> imgUrls) {
        this.iconUrl = imgUrls.get(0);
        this.imgUrls = imgUrls;
    }

    public Date getAddedDate() {
        return addedDate;
    }

    public void setAddedDate(Date addedDate) {
        this.addedDate = addedDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public boolean isNew() {
        // TODO Auto-generated method stub
        return productId == 0;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public int getCurAmount() {
        return curAmount;
    }

    public void setCurAmount(int curAmount) {
        this.curAmount = curAmount;
    }

    public double getUnitPrice() {
        return unitPrice;
    }

    public void setUnitPrice(double unitPrice) {
        this.unitPrice = unitPrice;
    }

    public double getUnitPriceCur() {
        return unitPriceCur;
    }

    public void setUnitPriceCur(double unitPriceCur) {
        this.unitPriceCur = unitPriceCur;
    }
    
    public void setCategoryId(int categoryId){
        this.categoryId = categoryId;
        if(null == category){
            category = new Category();
            category.setId(categoryId);
        }
    }
    
    public void setImgUrls(String string) {
       imgUrls = new ArrayList<String>();
       imgUrls.addAll(Arrays.asList((StringUtils.commaDelimitedListToStringArray(string))));
       this.iconUrl = imgUrls.get(0);
    }

    public int getCategoryId() {
        return categoryId;
    }

    public void addImage(String url) {
        if(null == imgUrls) imgUrls = new ArrayList<String>();
        imgUrls.add(url);    
    }

}
